﻿<!DOCTYPE html>
<html>
<head>
    <!--<base href="../" />-->
    <meta charset="UTF-8">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="/static/css/common/reset.css" />
    <link rel="stylesheet" href="/static/css/associate.css" />
    <link rel="stylesheet" href="/static/css/sweetalert.min.css" />
    <link rel="stylesheet" href="/static/js/simditor/styles/simditor.css" />
    <link rel="stylesheet" href="/static/js/simditor/styles/simditor-html.css" />
    <title>企业首页</title>
</head>
<body>
    <div class="associate" ng-app="myApp">
        <div id="divHeader"></div>
        <section class="assoc-content container clearfix">
            <div class="assoc-c-left fl">
                <div id="divNavigation"></div>
            </div>
            <div class="assoc-c-right fr" ng-controller="Ctrl">
                <form id="form">
                    <div class="assoc-cr-information fileAgent" ng-model="names">
                        <div class="reg-tcom-item mt10 clearfix">
                            <label>姓名：</label>
                            <input type="text" placeholder="" value="{{names.Name}}" name="UserName" required />
                            <input type="hidden" placeholder="" value="Agent" name="Role" />
                        </div>
                        <div class="reg-tcom-item mt10 clearfix">
                            <label>性别：</label>
                            <input type="radio" name="sex" value="male" checked>男
                            <input type="radio" name="sex" value="female">女
                        </div>
                        <div class="reg-tcom-item mt10 clearfix">
                            <label>手机：</label>
                            <input type="tel" placeholder="" value="{{names.Phone}} " name="Phone" />
                        </div>
                        <div class="reg-tcom-item mt10 clearfix">
                            <label>QQ：</label>
                            <input type="tel" placeholder="" value="{{names.QQ}} " name="QQ" />
                        </div>
                        <div class="reg-tcom-item mt10 clearfix">
                            <label>微信：</label>
                            <input type="tel" placeholder="" value="{{names.WeChart}} " name="Wechart" />
                        </div>
                        <div class="reg-tcom-item mt10 clearfix">
                            <label>邮箱：</label>
                            <input type="tel" placeholder="" value="{{names.Email}}" name="Email" />
                        </div>
                        <div class="reg-tcom-item mt10 school clearfix">
                            <label>所属院校：</label>
                            <select>
                                <option>广东省</option>
                            </select>
                            <select id="city" onchange="changeCity(this.value)">
                                <option>选择城市</option>
                            </select>
                            <select name="school" id="schoolNO" required>
                                <option value="">选择高校</option>
                            </select>
                        </div>
                        <div class="reg-tcom-item mt10 clearfix">
                            <label>个人简介：</label>
                            <input type="text" placeholder="" value="{{names.Resume}}" name="resume" />
                        </div>
                        <p class="assoc-crb-cardTitle file">重新提交认证证件</p>
                        <div class="reg-tAccount-uploadBtns clearfix">
                            <div class="reg-taUploadBtns-left fl" id="reg-taUploadBtns-left">
                                <a href="javascript:void(0)" class="reg-tauLeft-btn" name="">
                                    学生证封面上传
                                    <div class="form_control file">
                                        <input type="file" data-valid="isNonEmpty" data-tip="请上传学生证封面" data-error="请上传学生证封面" class="reg-tauLeft-btnInput required regInchargeFile" name="StuIDCardContent" />
                                    </div>
                                    <p class="reg-tauLeft-text">未上传</p>
                                </a>
                                <a href="javascript:void(0)" class="reg-tauLeft-btn" name="">
                                    学生证内页上传
                                    <div class="form_control file">
                                        <input type="file" data-valid="isNonEmpty" data-tip="请上传学生证内页" data-error="请上传学生证内页" class="reg-tauLeft-btnInput required regInchargeFile" name="StuIDCardCover" />
                                    </div>
                                    <p class="reg-tauLeft-text">未上传</p>
                                </a>
                            </div>
                            <div class="reg-taUploadBtns-right fr">
                                <p class="pl5">请根据提供规范上传个人证件照片</p>
                                <ul class="reg-tauRight-ul clearfix mt10" id="reg-tauRight-ul">
                                    <li><img src="/static/images/register6.png" /></li>
                                    <li><img src="/static/images/register7.png" /></li>
                                </ul>
                            </div>
                        </div>
                        <input type="button" class="assoc-crb-btn file" value="确认修改" id="btnSubmit" />
                    </div>
                </form>
            </div>
        </section>
    </div>
    <div id="divFooter"></div>
    <script type="text/javascript" src="/static/js/ref/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="/static/js/self/common.js"></script>
    <script type="text/javascript" src="/static/js/ref/angular.min.js"></script>
    <script src="/static/js/ref/linq.min.js"></script>
    <script src="/static/js/ref/jquery.validate.js"></script>

    <script type="text/javascript" src="/static/js/ref/sweetalert.min.js"></script>
    <script>
        $(function () {
            //选择文件
            $("#up-fileBook").on('change', function () {
                var filePath = document.getElementById("up-fileBookIn").files;
                var files_val = '';
                if (filePath) {
                    var fileNameBook = $(this).siblings('.up-fileNameBook');
                    files_val = ''
                    for (var i = 0; i < filePath.length; i++) {
                        files_val += '<span>' + filePath[i].name + '</span>'
                    }
                    fileNameBook.find('.up-file-content').html(files_val);
                    fileNameBook.show()
                }
            });
            $("#up-filePhoto").on('change', function () {
                var filePath = document.getElementById("up-filePhotoIn").files;
                var files_val = '';
                if (filePath) {
                    var fileNameBook = $(this).siblings('.up-fileNameBook');
                    files_val = ''
                    for (var i = 0; i < filePath.length; i++) {
                        files_val += '<span>' + filePath[i].name + '</span><br>'
                    }
                    fileNameBook.find('.up-file-content').html(files_val);
                    fileNameBook.show();
                }
            });
        });

        $("#divHeader").load("/wuc/header.html");
        $("#divFooter").load("/wuc/footer.html");
        $("#divNavigation").load("/wuc/navigation.html");

        function AfterCompleted(ctx) {
            if (ctx == null) {
                common.alertMessage("保存失败");
                return;
            }
            window.location = "/agent/agent/commuityinfo.html";
        }

        common.CreateController({ name: 'Ctrl', url: '/api/Agent/GetAgent', objType: 'dict' });
        var lstSchool;
        function ListSchool(ctx) {
            if (ctx == "" || ctx == null) {
                common.alertMessage("提交错误，请重试！");
                return;
            }
            lstSchool = ctx.ResponseList;

        }

        function changeCity(pno) {

            $("#schoolNO").empty();
            debugger;
            if (pno == "0" || pno == "" || pno == undefined)
                return;

            Enumerable.From(lstSchool).Where("$.CityNO == " + pno + "").ForEach(function (obj) {
                $("#schoolNO").append("<option value='" + obj.SchoolNO + "'>" + obj.SchoolName + "</option>")
            })
        }
        function GetCity(ctx) {
            if (ctx == "" || ctx == null) {
                common.alertMessage("提交错误，请重试！");
                return;
            }

            data = ctx.ResponseList;

            var str = [];

            //var res = Enumerable.From(data);

            var result = Enumerable.From(data).ForEach(function (obj) {

                if (obj.Code == 0)
                    return;

                if (str.indexOf(obj.Code) >= 0)
                    return;

                str.push(obj.Code);

                $("#city").append("<option value='" + obj.Code + "'>" + obj.Name + "</option>")
            });
        }

        $(document).ready(function () {
            common.commonAjax({ type: 'get', url: '/api/student/ListSchool', sMethod: ListSchool });
            common.commonAjax({ type: 'get', url: '/api/student/ListArea', sMethod: GetCity });

        });
        common.ValidateFormJQ('form', 'btnSubmit', submitSecondStep)
        function submitSecondStep() {
            common.FormAjax({ type: 'Post', url: '/api/Agent/UpdateAgentInfo', ID: "form", sMethod: AfterCompleted });
        };

        //设置账号信息选择文件
        $("#reg-taUploadBtns-left .regInchargeFile").on(' change', function () {

            /*var filePath = this.files;
            var files_val = '';
            files_val = "已上传：" + filePath[0].name;
            console.log(filePath);
            this.parentElement.parentElement.nextElementSibling.innerHTML = files_val;*/

            var $file = $(this);
            var index_ = $file.parent().parent().index();
            var li_ = $("#reg-tauRight-ul li");
            var fileObj = $file[0];
            var fileVal = fileObj.files[0].name;

            var fileSize = (fileObj.files[0].size / 1024).toFixed(1);
            if (!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(fileVal)) {
                alert("图片类型必须是.gif,jpg,jpeg,png,GIF,JPG,PNG中的一种")
                return false;
            } else if (fileSize > 1024) {
                alert("图片不能大于1M")
                return false;
            }

            var windowURL = window.URL || window.webkitURL;
            var dataURL;
            if (fileObj && fileObj.files && fileObj.files[0]) {
                dataURL = windowURL.createObjectURL(fileObj.files[0]);
                li_.eq(index_).find("img").attr('src', dataURL);
                this.parentElement.nextElementSibling.innerHTML = '已上传：' + fileObj.files[0].name;
            } else {

                dataURL = $file.val();
                var imgObj = document.getElementById("reg-tauRight-ul");
                var li_ = imgObj.getElementByTagName('li');
                // 两个坑:
                // 1、在设置filter属性时，元素必须已经存在在DOM树中，动态创建的Node，也需要在设置属性前加入到DOM中，先设置属性在加入，无效；
                // 2、src属性需要像下面的方式添加，上面的两种方式添加，无效；
                li_[index_].childNodes[0].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
                li_[index_].childNodes[0].filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;

            }

        });
    </script>
</body>

</html>
